---
title: "Column Groups"
---

Columns can be grouped in the grid's header using Column Groups. Column groups can be shown as open / closed to show / hide child Columns.

Column Groups are configured by providing a hierarchy of Column Definitions. If a Column Definition contains the `children` attribute then the grid treats it as a Column Group.

{% gridExampleRunner title="Basic Grouping" name="basic-grouping"  exampleHeight=550 /%}

```{% frameworkTransform=true %}
const gridOptions = {
    columnDefs: [
        {
            headerName: 'Name & Country',
            children: [
                { field: 'athlete' },
                { field: 'country' }
            ]
        },
        {
            headerName: 'Sports Results',
            children: [
                { columnGroupShow: 'closed', field: 'total' },
                { columnGroupShow: 'open', field: 'gold' },
                { columnGroupShow: 'open', field: 'silver' },
                { columnGroupShow: 'open', field: 'bronze' },
            ],
        }
    ]
}
```

Set the attribute `columnGroupShow` on the group's children to set the expand and collapse policy as follows:

* **`'open'`:** The child is only shown when the group is open.
* **`'closed'`:** The child is only shown when the group is closed.
* **`null`, `undefined`:** The child is always shown.

See [Group Column Properties](./column-properties/#reference-columnGroups) for all available properties.

## Group Defaults

Use `defaultColGroupDef` to set properties across all Column Groups.

{% gridExampleRunner title="Default Props" name="defaults"  exampleHeight=550 /%}

```{% frameworkTransform=true %}
const gridOptions = {
    defaultColGroupDef: {
        headerName: 'A shared prop for all Groups'
    }
}
```

## Multiple Levels

The example below demonstrates a grid with many column group header levels. Note the following:

* The API is used to open and close groups. To do this, you will need to provide your groups with an ID during the definition, or look up the groups ID via the API (as an ID is generated if you don't provide one).
* The `colDef.openByDefault` property is set on the E and F groups, resulting in these groups appearing as open by default.
* `defaultColGroupDef` and `defaultColDef` are used to apply a class to some of the headers. Using this technique, you can apply style to any of the header sections.

{% gridExampleRunner title="Advanced Grouping" name="advanced-grouping"  exampleHeight=680 /%}

## Groups & Column Pinning

Pinned columns break groups. So if you have a group with 10 columns, 4 of which are inside the pinned area, two groups will be created, one with 4 (pinned) and one with 6 (not pinned).

## Groups & Column Moving

If you move columns so that columns in a group are no longer adjacent, then the group will again be broken and displayed as one or more groups in the grid.

Sometimes you want columns of the group to always stick together. To achieve this, set the column group property `marryChildren=true`. The example below demonstrates the following:

* Both 'Athlete Details' and 'Sports Results' have `marryChildren=true`.
* If you move columns inside these groups, you will not be able to move the column out of the group. For example, if you drag 'Athlete', it is not possible to drag it out of the 'Athlete Details' group.
* If you move a non group column, e.g. Age, it will not be possible to place it in the middle of a group and hence impossible to break the group apart.
* It is possible to place a column between groups (e.g. you can place 'Age' between the 'Athlete Details' and 'Sports Results').

{% gridExampleRunner title="Marry Children" name="marry-children"  exampleHeight=560 /%}


## Resizing Groups

If you grab the group resize bar, it resizes each child in the group evenly distributing the new additional width. If you grab the child resize bar, only that one column will be resized.

{% imageCaption imagePath="resources/header-resize.png" alt="Header Resize" centered=true constrained=true width="30rem" /%}


## Auto Header Height

The header row for the column groups can have its height set automatically based on the content of the group header cells. This is most useful when using the `wrapHeaderText` column group property.

To enable this, set `autoHeaderHeight=true` on the column group definition you want to adjust the height for. If more than one column group has this property enabled, then the header row will be sized to the maximum of these
column groups' header cells to avoid content overflow.

The example below demonstrates using the `autoHeaderHeight` property in conjunction with the `wrapHeaderText` property, so that long column group names are fully displayed.

* Note that the long column group header names wrap onto another line
* Resize a column group down by dragging the resize handle on the column group header or child column headers left. Observe that the group header row will expand so the header cell content is still fully visible as it's getting wrapped on multiple lines.

{% gridExampleRunner title="Auto Header Height" name="auto-height" /%}

## Colouring Groups

The grid does not automatically colour the groups for you. However, you can achieve this by using the `headerClass` or `headerStyle` properties in the column definitions. These attributes can be applied to both individual columns and column groups.

```{% frameworkTransform=true suppressFrameworkContext=true %}
const gridOptions = {
    columnDefs: [
        // the CSS class name supplied to 'headerClass' will get applied to the header group
        { headerName: 'Athlete Details', headerClass: 'my-css-class', children: [] },
        { headerName: 'Medal Details', headerStyle: { backgroundColor: 'green', children: [] } }
    ]
}
```

## Text Alignment

The labels in the grouping headers are positioned with `display: flex`. To make the group headers right-aligned, add the following rule set in your application, after the grid's style sheets:

```css
.ag-header-group-cell-label {
    flex-direction: row-reverse;
}
```

## Sticky Label

When Column Groups are too wide, the **Header Label** is always visible while scrolling the grid horizontally. To suppress this behaviour, set the column group property `suppressStickyLabel=true`. The example below demonstrates the following:

* Both 'Athlete Details' and 'Sport Results' have `suppressStickyLabel=true`.
* If you scroll the grid horizontally, the header label will not remain visible as the column is partially scrolled out of view.

{% gridExampleRunner title="Sticky Label" name="suppress-sticky-label"  exampleHeight=560 /%}

## Group Changes

Similar to adding and removing columns, you can also add and remove column groups. If the column definitions passed in have column groups, then the columns will be grouped to the new configuration.

The example below shows adding and removing groups to columns. Note the following:

* Select **No Groups** to show all columns without any grouping.
* Select **Participant in Group** to show all participant columns only in a group.
* Select **Medals in Group** to show all medal columns only in a group.
* Select **Participant and Medals in Group** to show participant and medal columns in groups.
* As groups are added and removed, note that the state of the individual columns is preserved. To observe this, try moving, resizing, sorting, filtering etc and then add and remove groups, all the changed state will be preserved.

{% gridExampleRunner title="Group Changes" name="group-changes" /%}

The example above shows adding and removing groups. It is also possible to add and remove columns from groups. This is demonstrated in the example below. Note the following:

* The example has two groups: **Athlete Details** and **Sports Results**
* The example has two sets of columns, **Normal Cols** and **Extra Cols**.
* When you move from **Normal Cols** to **Extra Cols**, three new columns are added to the list. Two belong to the **Athlete Details** group, the other belongs to no group.

{% gridExampleRunner title="Group Changes 2" name="group-changes-2" /%}

## Column Height

By default the grid will resize the header cell to span the whole height of the header container, as shown in the example below.

Note the following:

* The **Age** column header cell is not under a column group cell, but spans the entire height of the header container.

{% gridExampleRunner title="Span Header Height" name="span-header-height"  exampleHeight=300 /%}

Using the **Column Property** `suppressSpanHeaderHeight` the Grid will balance the column headers with different number of levels with an empty column group header cell, as shown in the example below.

```{% frameworkTransform=true %}
const gridOptions = {
    columnDefs: [
        {
            headerName: 'Athlete Details',
            children: [
                { field: 'athlete' },
                { field: 'country' },
            ],
        },
        {
            field: 'age',
            width: 90,
            suppressSpanHeaderHeight: true,
        }
    ]
}
```

Note the following:

* The **Age** column has an empty column group header cell above it (shown with red borders).

{% gridExampleRunner title="Padded Header" name="padded-header"  exampleHeight=300 /%}

## Tooltips

Tooltips can be added to the Column Group Headers by using the `headerTooltip` property of the `ColGroupDef`.

The example below demonstrates using the `headerTooltip` property in the grid column groups.

{% gridExampleRunner title="Header Tooltip" name="group-header-tooltip" /%}

## Inner Header Group Component

When using the Header Group Component, the `agColumnHeaderGroup` component will display the header group name,
adjacent to the expand / collapse button.

This text value can be overridden with a [Custom Component](./components/) by setting the `innerHeaderGroupComponent` and `innerHeaderGroupComponentParams` properties
on the `headerGroupComponentParams` property. This is useful when you only need to implement a Component to customise the **Column Group Name** without having to reimplement
the other header group functionality such as the expand / collapse.

{% if isFramework("javascript", "angular", "react") %}
```js
colDef = {
    ...
    headerGroupComponentParams : {
        innerHeaderGroupComponent: MyInnerHeaderGroupComponent,
        innerHeaderGroupComponentParams: {
            currencySymbol: '£' // the pound symbol will be placed into params
        }
    }
}
```
{% /if %}

{% if isFramework("vue") %}
```js
colDef = {
    ...
    headerGroupComponentParams : {
        innerHeaderGroupComponent: 'MyInnerHeaderGroupComponent',
        innerHeaderGroupComponentParams: {
            currencySymbol: '£' // the pound symbol will be placed into params
        }
    }
}
```
{% /if %}

{% gridExampleRunner title="Custom Inner Header Group Component" name="inner-header-group-component" /%}

{% if isFramework("javascript", "angular") %}
Implement this interface to provide a custom inner header component.
{% /if %}
{% if isFramework("javascript") %}
### IInnerHeaderGroupComponent
{% interfaceDocumentation interfaceName="IInnerHeaderGroupComponent" config={"asCode":true } /%}
{% /if %}
{% if isFramework("angular") %}
### IInnerHeaderGroupAngularComp
{% interfaceDocumentation interfaceName="IInnerHeaderGroupAngularComp" config={"asCode":true } /%}
{% /if %}
{% if isFramework("javascript", "angular") %}
### IHeaderGroupParams
{% interfaceDocumentation interfaceName="IHeaderGroupParams" exclude=["template"] config={ "description": "" } /%}
{% /if %}
{% if isFramework("react") %}
```ts
const CustomInnerHeaderGroupComponent = (props: CustomInnerHeaderGroupProps) => {
    return <div>{props.displayName}</div>;
};
```
The following props are passed to the Custom Component (`CustomInnerHeaderGroupProps` interface).
### CustomInnerHeaderGroupProps
{% interfaceDocumentation interfaceName="CustomInnerHeaderGroupProps" config={ "description": "" } /%}
{% /if %}
{% if isFramework("vue") %}
Any valid Vue component can be a custom inner header group component, however it must implement the `IHeaderGroup` interface:

### IHeaderGroup
{% interfaceDocumentation interfaceName="IHeaderGroup" config={"asCode":true } /%}
{% /if %}

## Selecting Components

By default the grid uses the provided Header Group Component. To use a Custom Group Component set `headerGroupComponent` on the Column Definition.

{% partial file="./_column-def-javascript.mdoc" /%}
{% partial file="./_column-def-vue.mdoc" /%}

See [Registering Components](./components/) for an overview of registering components.

## Custom Group Component

The example below shows a Custom Column Group Component.

{% gridExampleRunner title="Header Group" name="header-group-component" /%}

As with Column Headers, the grid will always handle resize and column moving. The Custom Component is responsible for the following:

* **Group Open / Close:** If the group can expand (one or more columns visibility depends on the open / closed state of the group) then the Custom Component should handle the interaction with the user for opening and closing groups.

{% partial file="./_group-component-interface-javascript.mdoc" /%}
{% partial file="./_group-component-interface-angular.mdoc" /%}
{% partial file="./_group-component-interface-react.mdoc" /%}
{% partial file="./_group-component-interface-vue.mdoc" /%}

{% if isFramework("javascript", "angular", "vue") %}
{% interfaceDocumentation interfaceName="IHeaderGroupParams" /%}
{% /if %}

{% if isFramework("react") %}
{% interfaceDocumentation interfaceName="CustomHeaderGroupProps" /%}
{% /if %}

{% partial file="./_open-close-javascript.mdoc" /%}
{% partial file="./_open-close-angular.mdoc" /%}
{% partial file="./_open-close-react.mdoc" /%}
{% partial file="./_open-close-vue.mdoc" /%}

### Dynamic Tooltips

When using Custom Header Components it might be necessary to have a better control of how `Tooltips` are added instead of simply using the `headerTooltip` config. For this purpose, we provide the `setTooltip` method.
{% if isFramework("javascript", "angular", "vue") %}
{% interfaceDocumentation interfaceName="IHeaderGroupParams" names=["setTooltip"] /%}
{% /if %}

{% if isFramework("react") %}
{% interfaceDocumentation interfaceName="IHeaderGroupParams" names=["setTooltip"] /%}
{% /if %}

The example below demonstrates using the Dynamic Tooltips with a Custom Group Component.
* Note that only Group Headers where the text is not fully displayed will show tooltips.

{% gridExampleRunner title="Dynamic Group Header Tooltip" name="dynamic-tooltips" /%}
